/*****************************************************************
 *@Copyright all rights reserved © 2014 Yuga
 *@author Oplink OMS
 *Contact: zengkang007@gmail.com
 *****************************************************************/
package com.oplink.webems.modules.topo.dao;
import java.util.List;

import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Component;

import com.oplink.webems.common.persistence.BaseDao;
import com.oplink.webems.common.persistence.BaseDaoImpl;
import com.oplink.webems.modules.topo.entity.Topo;

/**
 * 告警DAO接口
 * @author Oplink OMS
 * @version 2014-09-01
 */
public interface TopoDao extends TopoDaoCustom, CrudRepository<Topo, Long> {

	@Modifying
	@Query("update Topo set delFlag='" + Topo.DEL_FLAG_DELETE + "' where id = ?1")
	public int deleteById(Long id);
	
	@Query("from Topo where topoId=?1")
	public List<Topo> findByTopoId(Long id);
	
}

/**
 * DAO自定义接口
 * @author Oplink OMS
 */
interface TopoDaoCustom extends BaseDao<Topo> {
	public boolean update(Topo t);
}

/**
 * DAO自定义接口实现
 * @author Oplink OMS
 */
@Component
class TopoDaoImpl extends BaseDaoImpl<Topo> implements TopoDaoCustom {
	public boolean update(Topo t){
		String hql = "update com.oplink.webems.modules.topo.entity.Topo set content=? where topoid=?";
		org.hibernate.Query q = this.getSession().createQuery(hql);
		q.setParameter(0, t.getContent());
		q.setParameter(1, t.getTopoid());
		int ret = q.executeUpdate();
		return ret == 1;
	}
}